package com.ityuwen.mengyagushi.album.api;

import com.alibaba.fastjson.JSONObject;
import com.ityuwen.mengyagushi.album.service.BaseCategoryService;
import com.ityuwen.mengyagushi.common.result.Result;
import com.ityuwen.mengyagushi.model.album.BaseAttribute;
import com.ityuwen.mengyagushi.model.album.BaseCategory3;
import com.ityuwen.mengyagushi.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"unchecked", "rawtypes"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;

	@GetMapping("getBaseCategoryList")
	public Result<List<JSONObject>> getBaseCategoryList(){
		List<JSONObject> jsonObjects = this.baseCategoryService.getBaseCategoryList();
		return Result.ok(jsonObjects);
	}

	@GetMapping("findAttribute/{category1Id}")
	public Result<List<BaseAttribute>> findAttribute(@PathVariable("category1Id")Long category1Id){
		List<BaseAttribute> baseAttributes = this.baseCategoryService.findAttribute(category1Id);
		return Result.ok(baseAttributes);
	}

	@GetMapping("findBaseCategoryView/{category3Id}")
	public Result<BaseCategoryView> findBaseCategoryView(@PathVariable("category3Id")Long category3Id) throws InterruptedException {
		BaseCategoryView baseCategoryView = this.baseCategoryService.findBaseCategoryView(category3Id);
		Thread.sleep(50);
		return Result.ok(baseCategoryView);
	}

	@GetMapping("findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable("category1Id")Long category1Id){
		List<BaseCategory3> baseCategory3s = this.baseCategoryService.findTopBaseCategory3(category1Id);
		return Result.ok(baseCategory3s);
	}

	@GetMapping("getBaseCategoryList/{category1Id}")
	public Result<JSONObject> getBaseCategoryList(@PathVariable("category1Id")Long category1Id){
		JSONObject category1 = this.baseCategoryService.getBaseCategoryList(category1Id);
		return Result.ok(category1);
	}
}

